home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_DrawGauge.c < prev    next >
C/C++ Source or Header  |  1996-10-03  |  5KB  |  258 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_GAUGE_KIND
  15. VOID
  16. LTP_GaugeFill(struct RastPort *rp,LONG pen,ObjectNode *node,LONG left,LONG right,LONG height)
  17. {
  18.     if(right)
  19.     {
  20.         LTP_SetAPen(rp,pen);
  21.         LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,right - left,height);
  22.     }
  23. }
  24.  
  25. VOID
  26. LTP_DrawTick(LayoutHandle *Handle,ObjectNode *Node,LONG Left,LONG Top)
  27. {
  28.     struct RastPort *rp = &Handle->RPort;
  29.  
  30.     Left += Node->Left;
  31.  
  32.     LTP_SetAPen(rp,Handle->ShadowPen);
  33.     LTP_DrawLine(rp,Left,Top,Left,Top + 1);
  34.  
  35.     LTP_SetAPen(rp,Handle->ShinePen);
  36.     LTP_DrawLine(rp,Left + 1,Top,Left + 1,Top + 1);
  37. }
  38.  
  39. VOID
  40. LTP_DrawGauge(LayoutHandle *handle,ObjectNode *node,LONG percent,BOOL fullRefresh)
  41. {
  42.     struct RastPort *rp = &handle->RPort;
  43.     LONG height = node->Height - (1 + 1);
  44.     LONG width = node->Width - (2 + 2);
  45.     UWORD *Pens = handle->DrawInfo->dri_Pens;
  46.     LONG fillPen = Pens[FILLPEN];
  47.     LONG backPen = Pens[BACKGROUNDPEN];
  48.     BOOL continuous;
  49.  
  50.     if(fullRefresh)
  51.     {
  52.         LTP_EraseBox(rp,node->Left,node->Top,node->Width,node->Height);
  53.  
  54.         if(node->Special.Gauge.NoTicks)
  55.             LTP_DrawBevelBox(handle,node);
  56.         else
  57.         {
  58.             LONG top = node->Top + node->Height - (handle->GlyphHeight + 2);
  59.  
  60.             LTP_DrawBevel(handle,node->Left,node->Top,node->Width,node->Height - (handle->InterHeight + handle->GlyphHeight + 2));
  61.  
  62.             LTP_SetPens(rp,handle->TextPen,0,JAM1);
  63.  
  64.             LTP_PrintText(rp,"0%",2,node->Left,top);
  65.             LTP_PrintText(rp,"100%",4,node->Left + node->Width - TextLength(rp,"100%",4),top);
  66.  
  67.             if(node->Width >= TextLength(rp,"0%50%100%",9) + 4 * handle->GlyphWidth)
  68.             {
  69.                 LONG i,left,total = node->Width - 2;
  70.  
  71.                 LTP_PrintText(rp,"50%",3,node->Left + (node->Width - TextLength(rp,"50%",3)) / 2,top);
  72.  
  73.                 top -= handle->InterHeight;
  74.  
  75.                 for (i = 0 ; i < 5 ; i++)
  76.                 {
  77.                     left = (total * i) / 4;
  78.  
  79.                     LTP_DrawTick(handle,node,left,top);
  80.                 }
  81.             }
  82.             else
  83.             {
  84.                 LONG i,left,total = node->Width - 2;
  85.  
  86.                 top -= handle->InterHeight;
  87.  
  88.                 for (i = 0; i < 3; i++)
  89.                 {
  90.                     left = (total * i) / 2;
  91.  
  92.                     LTP_DrawTick(handle,node,left,top);
  93.                 }
  94.             }
  95.         }
  96.     }
  97.  
  98.     if(node->Special.Gauge.Discrete)
  99.     {
  100.         if(width < 60)
  101.             continuous = TRUE;
  102.         else
  103.             continuous = FALSE;
  104.     }
  105.     else
  106.         continuous = TRUE;
  107.  
  108.     if(!node->Special.Gauge.NoTicks)
  109.         height -= handle->InterHeight + handle->GlyphHeight + 2;
  110.  
  111.     if(node->Special.Gauge.InfoLength && node->Special.Gauge.InfoText[0])
  112.     {
  113.         struct TextExtent Extent;
  114.         LONG len;
  115.         LONG textPen;
  116.         LONG mode;
  117.         LONG right;
  118.  
  119.         if(continuous)
  120.             LTP_GaugeFill(rp,fillPen,node,0,right = (width * percent) / 100,height);
  121.         else
  122.         {
  123.             LONG count;
  124.             LONG left;
  125.  
  126.             left = right = 0;
  127.  
  128.             if(count = (10 * percent) / 100)
  129.             {
  130.                 LONG chunk = width / 10,i;
  131.  
  132.                 for(i = 0 ; i < count ; i++)
  133.                 {
  134.                     LTP_SetAPen(rp,fillPen);
  135.                     LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,(chunk - 1),height);
  136.  
  137.                     left += chunk;
  138.                     right += chunk;
  139.  
  140.                     LTP_SetAPen(rp,backPen);
  141.                     LTP_FillBox(rp,node->Left + 2 + right - 1,node->Top + 1,1,height);
  142.                 }
  143.             }
  144.         }
  145.  
  146.         if(right < width)
  147.             LTP_GaugeFill(rp,backPen,node,right,width,height);
  148.  
  149.         if(handle->TextPen == fillPen)
  150.             textPen = Pens[FILLTEXTPEN];
  151.         else
  152.             textPen = handle->TextPen;
  153.  
  154.         if(textPen == fillPen || textPen == backPen)
  155.             mode = JAM1 | COMPLEMENT;
  156.         else
  157.             mode = JAM1;
  158.  
  159.         LTP_SetPens(rp,textPen,0,mode);
  160.  
  161.         len = TextFit(rp,node->Special.Gauge.InfoText,strlen(node->Special.Gauge.InfoText),&Extent,NULL,1,width,32767);
  162.  
  163.         LTP_PrintText(rp,node->Special.Gauge.InfoText,len,node->Left + 2 + (width - Extent.te_Width) / 2,node->Top + 1 + (height - handle->GlyphHeight) / 2);
  164.  
  165.         if(mode != JAM1)
  166.             SetDrMd(rp,JAM1);
  167.     }
  168.     else
  169.     {
  170.         LONG left,right,pen;
  171.         BOOL drawIt;
  172.  
  173.         drawIt = FALSE;
  174.  
  175.         if(continuous)
  176.         {
  177.             if(node->Current < percent)
  178.             {
  179.                 left    = (width * node->Current) / 100;
  180.                 right    = (width * percent) / 100;
  181.                 pen        = fillPen;
  182.                 drawIt    = TRUE;
  183.             }
  184.             else
  185.             {
  186.                 if(node->Current > percent)
  187.                 {
  188.                     left    = (width * percent) / 100;
  189.                     right    = (width * node->Current) / 100;
  190.                     pen        = backPen;
  191.                     drawIt    = TRUE;
  192.                 }
  193.             }
  194.         }
  195.         else
  196.         {
  197.             LONG count;
  198.  
  199.             count = (10 * percent) / 100;
  200.  
  201.             if(fullRefresh || count != node->Special.Gauge.LastPercentage)
  202.             {
  203.                 node->Special.Gauge.LastPercentage = count;
  204.  
  205.                 right = 0;
  206.  
  207.                 if(count)
  208.                 {
  209.                     LONG chunk = width / 10,i;
  210.  
  211.                     left = 0;
  212.  
  213.                     for(i = 0 ; i < count ; i++)
  214.                     {
  215.                         LTP_SetAPen(rp,fillPen);
  216.                         LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,(chunk - 1),height);
  217.  
  218.                         left += chunk;
  219.                         right += chunk;
  220.  
  221.                         LTP_SetAPen(rp,backPen);
  222.                         LTP_FillBox(rp,node->Left + 2 + right - 1,node->Top + 1,1,height);
  223.                     }
  224.                 }
  225.  
  226.                 if(right < width)
  227.                 {
  228.                     left    = right;
  229.                     right    = width;
  230.                     pen        = backPen;
  231.                     drawIt    = TRUE;
  232.                 }
  233.             }
  234.         }
  235.  
  236.         if(drawIt)
  237.             LTP_GaugeFill(rp,pen,node,left,right,height);
  238.     }
  239.  
  240.     if(node->Disabled)
  241.     {
  242.         UWORD Height;
  243.  
  244.         if(node->Special.Gauge.NoTicks)
  245.             Height = 0;
  246.         else
  247.             Height = handle->InterHeight + handle->GlyphHeight + 2;
  248.  
  249.  
  250.         LTP_GhostBox(rp,node->Left + 2,node->Top + 1,node->Width - 4,node->Height - 2 - Height,Pens[SHADOWPEN]);
  251.     }
  252.  
  253.     node->Current = percent;
  254.  
  255.     LTP_PutStorage(node);
  256. }
  257. #endif
  258.